//
//  gsMain.m
//  KingGE
//
//  Created by king on 10/4/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "gsMain.h"
#import "KingGEAppDelegate.h"
#import "gsTest.h"


@implementation gsMain

-(gsMain*) initWithFrame:(CGRect)frame andManager:(GameStateManager*)pManager {
	if (self = [super initWithFrame:frame andManager:pManager]) {
		NSLog(@"gsMain init");
	}
	return self;
}

-(void) Render {
	[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
	CGContextRef g = UIGraphicsGetCurrentContext();
	//fill background with gray
	CGContextSetFillColorWithColor(g, [UIColor blackColor].CGColor);
	CGContextFillRect(g, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));
	//draw text in white.
	CGContextSetFillColorWithColor(g, [UIColor whiteColor].CGColor);
	int FPS = [((KingGEAppDelegate*)m_pManager) getFramesPerSecond];
	NSString* strFPS = [NSString stringWithFormat:@"FPS %d", FPS]; 
	[strFPS drawAtPoint:CGPointMake(10.0,10.0) withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
	[@"Main state. Tap to change state" drawAtPoint:CGPointMake(10.0,50.0) withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
}

-(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
	UITouch* touch = [touches anyObject];
	NSUInteger numTaps = [touch tapCount];
	if (numTaps >= 1) {
		[m_pManager doStateChange:[gsTest class]];
	}
}

@end
